package com.kws.merchant.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kws.merchant.domain.FeedbackMessageEntity;
import com.kws.merchant.domain.vo.MerchantUserChatVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author : zhangbenting
 * @date : 2024/11/19 9:31
 * @Version: 1.0
 */
public interface FeedbackMessageMapper extends BaseMapper<FeedbackMessageEntity> {


    @Select("SELECT " +
            " count(id) " +
            "FROM " +
            " tb_merchant_user_chat  " +
            "WHERE " +
            " message_type = 1 " +
            " AND to_user = ${userId}")
    Long getLogisticsMessageCount(@Param("userId") Long userId);


    @Select("SELECT " +
            " * " +
            "FROM " +
            " tb_merchant_user_chat  " +
            "WHERE " +
            " message_type = 1 " +
            " AND to_user = ${userId}" +
            " limit ${page},${size}")
    List<MerchantUserChatVo> getLogisticsMessage(@Param("userId") Long userId,
                                                 @Param("page") Integer page,
                                                 @Param("size") Integer size);

    @Select("SELECT " +
            " count(id) " +
            "FROM " +
            " tb_merchant_user_chat  " +
            "WHERE " +
            " message_type = 5 " +
            " AND to_user = ${userId}")
    Long getNoticeMessageCount(@Param("userId") Long userId);

    @Select("SELECT " +
            " * " +
            "FROM " +
            " tb_merchant_user_chat  " +
            "WHERE " +
            " message_type = 5 " +
            " AND to_user = ${userId}" +
            " limit ${page},${size}")
    List<MerchantUserChatVo> getNoticeMessage(@Param("userId") Long userId,
                                              @Param("page") Integer page,
                                              @Param("size") Integer size);

    @Select("SELECT " +
            " * " +
            " FROM " +
            " tb_merchant_user_chat  " +
            " WHERE " +
            " `status` = 1 " +
            " AND to_user = 1")
    List<MerchantUserChatVo> getUserMessageCount(@Param("userId") Long userId);

    @Select("SELECT * FROM `tb_merchant_user_chat` WHERE message_type = 4 AND `status` = 1 AND to_user = ${userId}")
    List<MerchantUserChatVo> getUserServeMessage(@Param("userId") Long userId);

    @Update("update tb_merchant_user_chat set status=0 where send_user=${sendUser} and to_user=${userId}")
    boolean readMessage(@Param("sendUser") Long sendUser, @Param("userId") Long userId);
}
